﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UcSpreadSheet.ascx.cs" Inherits="SpreadSheetFramework.UcSpreadSheet" %>
<%@ Register assembly="DevExpress.Web.ASPxSpreadsheet.v14.2, Version=14.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxSpreadsheet" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.v14.2, Version=14.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web" tagprefix="dx" %>



<style type="text/css">
    .righ-menu { visibility: hidden; }
</style>
<div style="width: 100%">
    <dx:ASPxRibbon ID="ASPxRibbon1" runat="server" ShowFileTab="False" Width="100%" EnableTheming="True" Theme="Default" AllowMinimize="False">
        <Tabs>
            <dx:RibbonTab Name="Tools" Text="Công cụ">
                <Groups>
                    <dx:RibbonGroup Name="Edit" Text="Chỉnh sửa">
                        <Items>
                            <dx:RibbonButtonItem Name="undo" Size="Large" ToolTip="Undo">
                                <LargeImage IconID="history_undo_32x32">
                                </LargeImage>
                                <SmallImage IconID="history_undo_16x16">
                                </SmallImage>
                            </dx:RibbonButtonItem>
                            <dx:RibbonButtonItem Name="redo" Size="Large" ToolTip="Redo">
                                <LargeImage IconID="history_redo_32x32">
                                </LargeImage>
                                <SmallImage IconID="history_redo_16x16">
                                </SmallImage>
                            </dx:RibbonButtonItem>
                            <dx:RibbonButtonItem Name="insertRow" Size="Large" ToolTip="Thêm dòng">
                                <LargeImage IconID="reports_emptytablerowseparator_32x32">
                                </LargeImage>
                            </dx:RibbonButtonItem>
                            <dx:RibbonButtonItem Name="deleteRow" Size="Large" ToolTip="Xóa dòng">
                                <LargeImage IconID="reports_none_32x32">
                                </LargeImage>
                            </dx:RibbonButtonItem>
                            <dx:RibbonButtonItem Name="copy" Size="Large" ToolTip="Copy">
                                <LargeImage IconID="edit_copy_32x32">
                                </LargeImage>
                            </dx:RibbonButtonItem>
                            <dx:RibbonButtonItem Name="paste" Size="Large" ToolTip="Paste">
                                <LargeImage IconID="edit_paste_32x32">
                                </LargeImage>
                            </dx:RibbonButtonItem>
                        </Items>
                    </dx:RibbonGroup>
                    <dx:RibbonGroup Name="Tải dữ liệu" Text="Tải dữ liệu">
                        <Items>
                            <dx:RibbonTemplateItem Size="Large">
                                <Template>
                                   <dx:ASPxButton ID="btDownload"  runat="server" Width="16px" OnClick="btDownload_Onclick" Height="16px" ImagePosition="Top" BackColor="White">
                                        <Image IconID="save_saveto_32x32">
                                        </Image>
                                        <PressedStyle BackColor="White">
                                        </PressedStyle>
                                        <HoverStyle BackColor="White">
                                        </HoverStyle>
                                        <FocusRectBorder BorderColor="White" BorderStyle="None" />
                                        <Border BorderStyle="None" />
                                    </dx:ASPxButton>
                                </Template>
                            </dx:RibbonTemplateItem>
                        </Items>
                    </dx:RibbonGroup>
                </Groups>
            </dx:RibbonTab>
            <dx:RibbonTab Name="Calculate" Text="Tính toán">
                <Groups>
                    <dx:RibbonGroup Name="Tính toán" Text="Tính toán">
                        <Items>
                            <dx:RibbonTemplateItem Size="Large">
                                <Template>
                                     
                                    <dx:ASPxButton ID="btCalculte" runat="server" Text="Tính toán" Width="60px" OnClick="btCalculte_Onclick" Height="60px"></dx:ASPxButton>
                                  
                                </Template>
                            </dx:RibbonTemplateItem>
                        </Items>
                    </dx:RibbonGroup>
                    <dx:RibbonGroup Name="Nhập lại" Text="Nhập lại">
                        <Items>
                            <dx:RibbonTemplateItem Size="Large">
                                <Template>
                                    <dx:ASPxButton ID="btResetInput" runat="server" Text="Nhập lại" Width="60px" OnClick="btResetInput_Onclick" Height="60px"></dx:ASPxButton>
                                </Template>
                            </dx:RibbonTemplateItem>
                        </Items>
                    </dx:RibbonGroup>
                    <dx:RibbonGroup Name="Result" Text="Kết quả tính toán" >
                        <Items>
                            <dx:RibbonTemplateItem Size="Large" >
                                <Template>
                                    <div >
                                        <dx:ASPxGridView ID="gridError" KeyFieldName="RangeInfo" Width="900px" OnLoad="gridError_Onload" runat="server" AutoGenerateColumns="False" ClientInstanceName="gridError">
                                            <ClientSideEvents SelectionChanged="function(s, e) {
	                                                                                            if (e.isSelected) 
	                                                                                            {
		                                                                                            var key = s.GetRowKey(e.visibleIndex);
		                                                                                            OnGetRowValues (key);
	                                                                                            }
                                                                                            }" />
                                            <Columns>
                                                <dx:GridViewDataTextColumn Name="colError" FieldName="Error"  VisibleIndex="0">
                                                </dx:GridViewDataTextColumn>
                                                <dx:GridViewDataTextColumn FieldName="RangeInfo" Name="RangeInfo" Visible="False" VisibleIndex="1">
                                                </dx:GridViewDataTextColumn>
                                            </Columns>
                                            <SettingsBehavior AllowDragDrop="False" AllowGroup="False" AllowSort="False" AllowFocusedRow="True" AllowSelectByRowClick="True" AllowSelectSingleRowOnly="True" />
                                            <SettingsPager Mode="ShowAllRecords" Visible="False">
                                            </SettingsPager>
                                            <Settings ShowColumnHeaders="False" VerticalScrollBarMode="Visible" VerticalScrollableHeight="60" />
                                            <SettingsText EmptyDataRow=" " />
                                            <SettingsDataSecurity AllowDelete="False" AllowEdit="False" AllowInsert="False" />
                                        </dx:ASPxGridView>

                                        <script>
                                            function OnGetRowValues(values) {
                                                spreadsheet.PerformCallback('er' + values);
                                            }
                                        </script>
                                    </div>
                                </Template>
                            </dx:RibbonTemplateItem>
                        </Items>
                    </dx:RibbonGroup>
                </Groups>
            </dx:RibbonTab>
        </Tabs>
        <ClientSideEvents CommandExecuted="function(s, e) {
            var param= procRibbon(e);
            if(param!='-999')
	            spreadsheet.PerformCallback('rb'+e.item.name+':'+param );
        }" />
    </dx:ASPxRibbon>
    <script>
        function procRibbon(e) {
            var rv = "";
            var cell = null;
            switch (e.item.name) {
            case 'undo':
                rv = "";
                break;
            case 'redo':
                rv = "";
                break;
            case 'insertRow':
                cell = spreadsheet.GetSelection();
                if (cell)
                    rv = cell.topRowIndex;
                else {
                    alert("Bạn chưa chọn dòng để thêm");
                    rv = "-999";
                }
                break;
            case 'deleteRow':
                cell = spreadsheet.GetSelection();
                if (cell)
                    rv = cell.topRowIndex;
                else {
                    alert("Bạn chưa chọn dòng để xóa");
                    rv = "-999";
                }
                break;
            }
            return rv;
        }

    </script>
</div>
<div id="spdiv" style="width: 100%;height: 100%;clear: both" >
    <dx:ASPxSpreadsheet ID="spreadsheet" runat="server" ClientInstanceName="spreadsheet" EnableClientSideAPI="True" Width="100%" OnCallback="spreadsheet_Callback" RibbonMode="None">
        <StylesPopupMenu>
            <Control Font-Size="0px">
            </Control>
            <Style Font-Size="0px">
                
                
                
            </Style>
            <Item Height="0px" Width="0px" Font-Size="0px">
                <Paddings PaddingBottom="0px" PaddingLeft="0px" PaddingRight="0px" PaddingTop="0px" />
                <BackgroundImage HorizontalPosition="-100" VerticalPosition="-100" />
            </Item>
            <SubMenuItem Height="0px" Width="0px">
            </SubMenuItem>
        </StylesPopupMenu>
        <SettingsDialogForm>
            <SaveFileDialog DisplaySectionMode="ShowAllSections"></SaveFileDialog>
        </SettingsDialogForm>

        <SettingsDocumentSelector>
            <EditingSettings TemporaryFolder="~\App_Data\UploadTemp\"></EditingSettings>
        </SettingsDocumentSelector>
    </dx:ASPxSpreadsheet>
    <script>
        function PasteData(evt) {
            evt.preventDefault();
            var clipText = "";
            var ua = window.navigator.userAgent;
            var msie = ua.indexOf("Trident");
            if (msie > 0) {
                clipText = window.clipboardData.getData('Text');
            } else {
                clipText = evt.clipboardData.getData('Text');
            }
            var cell = spreadsheet.GetSelection();
            if (cell)
                spreadsheet.PerformCallback("cv" + cell.activeCellColumnIndex + ":" + cell.activeCellRowIndex + "|" + clipText);

            //lert(clipText);
        }

        function CopyData(evt) {
            //  evt.preventDefault();
//            window.clipboardData.setData('text','');
//            evt.clipboardData.setData('text', '');
//            alert(window.clipboardData.getData('Text'));
//            alert(evt.clipboardData.getData('Text'));
        }

        document.getElementById('UcSpreadSheet1_spreadsheet').addEventListener("paste", PasteData, false);
        document.getElementById('UcSpreadSheet1_spreadsheet').addEventListener("copy", CopyData, false);
        document.getElementById('UcSpreadSheet1_spreadsheet').onmousedown = function(e) {
            if (e.which == 3) {
                // alert(e.clientX + "-" + e.clientY);
                popupMenu.ShowAtPos(e.clientX + ASPxClientUtils.GetDocumentScrollLeft(), e.clientY + ASPxClientUtils.GetDocumentScrollTop());
            }
        };
    </script>

</div>
    <dx:ASPxPopupMenu ID="popupMenu" runat="server" ClientInstanceName="popupMenu" PopupElementID="spreadsheet">
        <ClientSideEvents ItemClick="function(s, e) {
             var param= procRibbon(e);
            if(param!='-999')
	            spreadsheet.PerformCallback('rb'+e.item.name+':'+param );}" />
        <Items>
            <dx:MenuItem Name="insertRow" Text="Insert Row">
                <Image IconID="reports_emptytablerowseparator_16x16">
                </Image>
            </dx:MenuItem>
            <dx:MenuItem Name="deleteRow" Text="Delete Row">
                <Image IconID="reports_none_16x16">
                </Image>
            </dx:MenuItem>
            <dx:MenuItem Name="copy" Text="Copy">
                <Image IconID="edit_copy_16x16">
                </Image>
            </dx:MenuItem>
            <dx:MenuItem Name="paste" Text="Paste">
                <Image IconID="edit_paste_16x16">
                </Image>
            </dx:MenuItem>
        </Items>
    </dx:ASPxPopupMenu>
    
    